Imports System.Windows.Forms
Imports Vintasoft.Imaging.Codecs.Tiff

Public Partial Class TagModifyForm
	Inherits Form

	#Region "Fields"

	Private _tagDataType As Integer = CInt(TiffTagDataType.Ascii)

	#End Region


	#Region "Constructor"

	Public Sub New(tagDataType As Integer)
		InitializeComponent()

		_tagDataType = tagDataType
		Select Case _tagDataType
			Case CInt(TiffTagDataType.[Short]), CInt(TiffTagDataType.SShort), CInt(TiffTagDataType.[Long]), CInt(TiffTagDataType.SLong)
				groupStringValue.Visible = False
				groupIntegerValue.Visible = True
				groupDoubleValue.Visible = False
				groupRationalValue.Visible = False
				Exit Select

			Case CInt(TiffTagDataType.Float), CInt(TiffTagDataType.[Double])
				groupStringValue.Visible = False
				groupIntegerValue.Visible = False
				groupDoubleValue.Visible = True
				groupRationalValue.Visible = False
				Exit Select

			Case CInt(TiffTagDataType.Rational), CInt(TiffTagDataType.SRational)
				groupStringValue.Visible = False
				groupIntegerValue.Visible = False
				groupDoubleValue.Visible = False
				groupRationalValue.Visible = True
				Exit Select
		End Select

		numNumerator.Maximum = Decimal.MaxValue
		numDenominator.Maximum = Decimal.MaxValue

		Invalidate()
	End Sub

	#End Region


	#Region "Properties"

	Public Property StringValue() As String
		Get
			Return stringValueTextBox.Text
		End Get
		Set
			stringValueTextBox.Text = value
		End Set
	End Property

	Public Property IntegerValue() As Integer
		Get
			Return CInt(Math.Truncate(numInteger.Value))
		End Get
		Set
			numInteger.Value = value
		End Set
	End Property

	Public Property DoubleValue() As Double
		Get
			Dim value As Double
			If Double.TryParse(textDoubleValue.Text, value) Then
				Return value
			Else
				Return 0.0
			End If
		End Get
		Set
			textDoubleValue.Text = value.ToString()
		End Set
	End Property

	Public Property NumeratorValue() As Integer
		Get
			Return CInt(Math.Truncate(numNumerator.Value))
		End Get
		Set
			numNumerator.Value = value
		End Set
	End Property

	Public Property DenominatorValue() As Integer
		Get
			Return CInt(Math.Truncate(numDenominator.Value))
		End Get
		Set
			numDenominator.Value = value
		End Set
	End Property

	#End Region


	#Region "Methods"

	Private Sub bOk_Click(sender As Object, e As EventArgs)
		If _tagDataType = CInt(TiffTagDataType.Float) OrElse _tagDataType = CInt(TiffTagDataType.[Double]) Then
			Dim value As Double
			If Not Double.TryParse(textDoubleValue.Text, value) Then
				MessageBox.Show("Double value is incorrect!", "Add tag")
				Return
			End If
		End If

		DialogResult = System.Windows.Forms.DialogResult.OK
	End Sub

	Private Sub bCancel_Click(sender As Object, e As EventArgs)
		DialogResult = System.Windows.Forms.DialogResult.Cancel
	End Sub

	#End Region

End Class
